<%
layout("/layouts/platform.html"){
%>
<header class="header navbar bg-white shadow">
    <div class="btn-group tool-button">
        <a class="btn btn-primary navbar-btn" href="${base}/platform/sys/menu" data-pjax id="goback"><i class="ti-angle-left"></i> 返回</a>
    </div>
</header>

<div class="content-wrap">
    <div class="wrapper" style="min-height:500px;">
        <section class="panel panel-form">
            <form id="unitAddForm" role="form" class="form-horizontal parsley-form" data-parsley-validate
                  action="${base}/platform/sys/menu/editDo" method="post">
                <input type="hidden" id="id" name="id" value="${obj.id!}">
                <input type="hidden" id="isShow" name="isShow" value="${obj.isShow!}">
                <input type="hidden" id="hasChildren" name="hasChildren" value="${obj.hasChildren!}">
                <input type="hidden" id="oldPermission" name="oldPermission" value="${obj.permission!}">
                <div class="row mb10">
                    <div class="col-lg-12">
                        <div class="form-group has-feedback">
                            <label for="parentId" class="col-sm-2 control-label">上级菜单</label>

                            <div class="col-sm-8">
                                <input id="parentId" type="text" class="form-control" placeholder="顶级菜单" disabled
                                       value="<%if(!isEmpty(parentMenu)){%>${parentMenu.name}<%}%>"/>
                                <input type="hidden" name="parentId" value="<%if(!isEmpty(parentMenu)){%>${parentMenu.id}<%}%>">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="type" class="col-sm-2 control-label">权限类型</label>
                            <div class="col-sm-8">
                                <select id="type" name="type" class="form-control">
                                    <option value="menu" <%if(obj.type=="menu"){%>selected<%}%>>菜单</option>
                                    <option value="data" <%if(obj.type=="data"){%>selected<%}%>>数据</option>
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="name" class="col-sm-2 control-label">名&nbsp;&nbsp;称</label>

                            <div class="col-sm-8">
                                <input type="text" id="name" class="form-control" name="name" value="${obj.name!}" data-parsley-required="true"
                                       placeholder="名称">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="permission" class="col-sm-2 control-label">权限标识</label>

                            <div class="col-sm-8">
                                <input type="text" id="permission" name="permission" value="${obj.permission!}"  class="form-control" placeholder="权限标识" data-parsley-required="true">

                                <p class="help-block no-m">例如：sys.manager.unit</p>
                            </div>
                        </div>
                        <div id="divId" <%if(obj.type=="data"){%>style="display:none;"<%}%>>
                        <div class="form-group">
                            <label for="href" class="col-sm-2 control-label">URL</label>

                            <div class="col-sm-8">
                                <input type="text" id="href" name="href" value="${obj.href!}" class="form-control" placeholder="URL">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="target" class="col-sm-2 control-label">target</label>
                            <div class="col-sm-8">
                                <input type="text" id="target" name="target" value="${obj.target!}" class="form-control" placeholder="data-pjax">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="icon" class="col-sm-2 control-label">图标</label>
                            <div class="col-sm-8">
                                <input id="icon" type="text" name="icon" value="${obj.icon!}" class="form-control" placeholder="图标样式">
                                <p class="help-block no-m">效果预览：<i id="iconPreview" class="<%if(!isEmpty(obj.icon)){%>${obj.icon!}<%}else{%>ti-plus<%}%>"></i></p>
                            </div>
                        </div>
                        </div>

                    </div>
                </div>
                <div class="col-lg-3"></div>
                <div class="col-lg-6">
                    <div class="form-group text-center">
                        <label></label>

                        <div>
                            <button class="btn btn-primary btn-block btn-lg btn-parsley" data-loading-text="正在提交...">提 交</button>
                        </div>
                    </div>
                </div>
            </form>
        </section>

    </div>
</div>
<a class="exit-offscreen"></a>
<script language="JavaScript">
    $(document).ready(function () {
        //图标样式 实时预览
        $("#icon").on("keyup", function(){
            $("#iconPreview").attr("class", $(this).val());
        });
        $("#type").on("change",function(){
            if($(this).val()=="menu"){
                $("#divId").show();
            }else{
                $("#href").val("");
                $("#target").val("");
                $("#icon").val("");
                $("#divId").hide();
            }
        });
        $('#unitAddForm').ajaxForm({
            dataType: 'json',
            beforeSubmit: function (arr, form, options) {
                form.find("button:submit").button("loading");
            },
            success: function (data, statusText, xhr, form) {
                if (data.code==0) {
                    Toast.success(data.msg);
                    setTimeout(function () {
                        $("#goback").trigger("click");
                    }, 1000);
                } else {
                    Toast.error(data.msg);
                }
                form.find("button:submit").button("reset");
            }
        });
    });
</script>


<%}%>